#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <ctype.h>
#include <pthread.h>
#include <assert.h>
#include <termios.h>
#include <signal.h>
#include "in_temp.h"

/**z7测温**/

#define DEBUG    0

#if DEBUG
    #define DBG_MSG(fmt, args...)    fprintf(stdout, fmt, ##args)
#else
    #define DBG_MSG(fmt, args...)
#endif


#define TEMP  (1<<12) //测试温度系数4096

int measure()
{
	FILE *stream;
	int temp, temp_value;


	char buf[20] = "";
	if ((stream = fopen(SYS_PATH_TEMP_IIO_VALUE, "w+"))== NULL)
	{
		fprintf(stderr,"Cannot open output file.\n");
		return 1;
	}
	fseek(stream, SEEK_SET, 0);
	fread(buf, sizeof(char), sizeof(buf), stream);
	temp=atoi(buf);

	temp_value = temp * 503.975/TEMP - 273.15;
	DBG_MSG("The CPU temperature is %.2f ℃   \r\n", temp * 503.975/TEMP - 273.15);

	fclose(stream);
	return temp_value;
}
